﻿app.directive("createWord", function () {
    return {
        restrict: "A",
        link: function (scope, element, attrs) {
            scope.$watch('getFromRoom', function (newVal, oldVal) {
                if (newVal) {

                }
            });
        }
    };
});
app.directive('animateShowHide', function () {
    return {
        restrict: "A",
        link: function(scope, element, attrs) {
            scope.$watch(attrs.animateShowHide, function() {
                //$('.word-item').height(30);
                element.append('<div class="word-item" data-ng-repeat="l in listWord" " style="height:auto;">' +
                    '<span>WordName:</span><input class="WordName" type="text" />' +
                    '<span>Type:</span><input class="Type" type="text" />' +
                    '<span>Meaning:</span><input class="Meaning" type="text" />' +
                    '<span>Pronounce:</span><input class="Pronounce" type="text" />' +
                    '</div>').fadeIn('fast');
            });
        }
    };
});
app.directive('passwordValidate', function () {
    return {
        require: 'ngModel',
        link: function (scope, elm, attrs, ctrl) {
            ctrl.$parsers.unshift(function (viewValue) {

                scope.ValidLength = (viewValue && viewValue.length >= 8 ? 'valid' : undefined);
                if (scope.ValidLength) {
                    ctrl.$setValidity('pwd', true);
                    return viewValue;
                } else {
                    ctrl.$setValidity('pwd', false);
                    return undefined;
                }
                

            });
        }
    };
});
app.directive('rePasswordValidate', function () {
    return {
        require: 'ngModel',
        link: function (scope, elm, attrs, ctrl) {
            ctrl.$parsers.unshift(function (viewValue) {

                scope.ValidLength = (viewValue && viewValue.length >= 8 ? 'valid' : undefined);
                if (scope.ValidLength) {
                    ctrl.$setValidity('pwd', true);
                    return viewValue;
                } else {
                    ctrl.$setValidity('pwd', false);
                    return undefined;
                }
                

            });
        }
    };
});
app.directive('validPasswordC', function () {
    return {
        require: 'ngModel',
        link: function (scope, elm, attrs, ctrl) {
            ctrl.$parsers.unshift(function (viewValue, $scope) {
                var noMatch = viewValue != scope.myForm.password.$viewValue;
                ctrl.$setValidity('noMatch', !noMatch);
            });
        }
    };
});
app.directive('customDragArea', function (snapRemote) {
    return {
        restrict: 'AE',
        link: function (scope, element, attrs) {
            snapRemote.getSnapper().then(function (snapper) {
                snapper.settings({
                    dragger: element[0]
                });
            });
        }
    };
});
//app.directive('ngScroll', function () {
//    return {
//        replace: false,
//        restrict: 'A',
//        link: function (scope, element, attr) {
//            scope.$watch(attr.ngScroll, function (value) {
//                new iScroll(document.querySelector('#wrapper'), {
//                    snap: true,
//                    momentum: true,
//                    hScrollbar: true
//                });
//            });
//        }
//    };
//});
app.directive('ngBlur', function () {
    return function (scope, elem, attrs) {
        elem.bind('blur', function () {
            scope.$apply(attrs.ngBlur);
        });
    };
});